package com.woohua.demo.leetCode.simple;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @version 1.0
 * @author: woo hua
 * @DATE 2022/9/6 15:54
 * @description:
 */
public class Solution {

    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> hash = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(hash.containsKey(target - nums[i])) {
                return new int[]{hash.get(target - nums[i]), i};
            }
            hash.put(nums[i], i);
        }
        return new int[]{};
    }

    public static void main(String[] args) {
        int[] nums = new int[]{3,3};
        int target = 6;
        int[] ints = twoSum(nums, target);
        Arrays.asList(ints).stream().forEach(System.out::print);
    }
}
